home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / utils / symbol-syntax.el.z / symbol-syntax.el
Encoding:
Text File  |  1998-05-21  |  3.9 KB  |  123 lines

  1. ;;; symbol-syntax.el --- find chars with symbol syntax
  2.  
  3. ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  4. ;; Copyright (C) 1995 Sun Microsystems.
  5.  
  6. ;; Created by: JBW, JBW@_CORTEZ
  7. ;; Created on: Wed Jun 20 15:15:34 1990
  8. ;; Last modified by: Ben Wing, wing@666.com
  9. ;; Last modified on: Mon Oct  2 02:32:05 GMT 1995
  10. ;; Filename: symbol-syntax.el
  11. ;; Keywords: matching
  12.  
  13. ;; This file is part of XEmacs.
  14.  
  15. ;; XEmacs is free software; you can redistribute it and/or modify it
  16. ;; under the terms of the GNU General Public License as published by
  17. ;; the Free Software Foundation; either version 2, or (at your option)
  18. ;; any later version.
  19.  
  20. ;; XEmacs is distributed in the hope that it will be useful, but
  21. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23. ;; General Public License for more details.
  24.  
  25. ;; You should have received a copy of the GNU General Public License
  26. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  27. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  28. ;; Boston, MA 02111-1307, USA.
  29.  
  30. ;;; Synched up with: Not in FSF.
  31.  
  32. (defvar symbol-syntax-table-alist nil)
  33. ;;  '((c-mode-syntax-table)
  34. ;;    (emacs-lisp-mode-syntax-table)
  35. ;;    (lisp-mode-syntax-table)
  36. ;;    (text-mode-syntax-table)))
  37.  
  38. (defun update-symbol-syntax-table-alist ()
  39.   (let ((alist symbol-syntax-table-alist)
  40.     item)
  41.     (while (consp alist)
  42.       (cond ((null (car alist))
  43.          (error "Missing alist item"))
  44.         ((null (car (car alist)))
  45.          (error "Alist item with null car"))
  46.         ;; this functionality not used
  47.         ((symbolp (setq item (car (car alist))))
  48.          (or (null (cdr (car alist)))
  49.          (error "Alist item expected to have null cdr"))
  50.          (while (symbolp item)
  51.            (setq item (symbol-value item)))
  52.          (setcar (car alist) item)))
  53.       (cond ((not (syntax-table-p (car (car alist))))
  54.          (error "Alist item car expected to be symbol table"))
  55.         ((null (cdr (car alist)))
  56.          (setcdr (car alist)
  57.              (make-symbol-syntax-table (car (car alist))))))
  58.       (setq alist (cdr alist)))))
  59.  
  60. (defun get-symbol-syntax-table (norm-table)
  61.   (let (result)
  62.     (if (setq result (assq norm-table symbol-syntax-table-alist))
  63.     nil
  64.       (update-symbol-syntax-table-alist)
  65.       (if (setq result (assq norm-table symbol-syntax-table-alist))
  66.       nil
  67.     (setq symbol-syntax-table-alist
  68.           (cons (list norm-table)
  69.             symbol-syntax-table-alist))
  70.     (update-symbol-syntax-table-alist)
  71.     (or (setq result (assq norm-table symbol-syntax-table-alist))
  72.         (error "Syntax table missing from symbol-syntax-table-alist"))))
  73.     (or (setq result (cdr result))
  74.     (error "Alist item has null cdr"))
  75.     (or (syntax-table-p result)
  76.     (error "Non-syntax-table item in alist"))
  77.     result))
  78.  
  79. (defun make-symbol-syntax-table (in-table)
  80.   (let ((out-table (copy-syntax-table in-table)))
  81.     (map-syntax-table
  82.      #'(lambda (key value)
  83.      (if (eq ?_ (char-syntax-from-code value))
  84.          (put-char-table key (set-char-syntax-in-code value ?w)
  85.                  out-table))
  86.      nil)
  87.      out-table)
  88.     out-table))
  89.  
  90. ;; stuff for examining contents of syntax tables
  91. ;;(show-chars-with-syntax
  92. ;; '(c-mode-syntax-table
  93. ;;   emacs-lisp-mode-syntax-table
  94. ;;   lisp-mode-syntax-table
  95. ;;   text-mode-syntax-table)
  96. ;; ?_)
  97.  
  98. (defun show-chars-with-syntax (tables syntax)
  99.   (let ((osyn (syntax-table))
  100.     (schars nil))
  101.     (unwind-protect
  102.     (while (consp tables)
  103.       (let* ((chars nil)
  104.          (table-symbol (car tables))
  105.          (table table-symbol)
  106.          (i 0))
  107.         (or (symbolp table-symbol)
  108.         (error "bad argument non-symbol"))
  109.         (while (symbolp table)
  110.           (setq table (symbol-value table)))
  111.         (map-syntax-table
  112.          #'(lambda (key value)
  113.          (if (eq syntax (char-syntax-from-code value))
  114.              (setq chars (cons key chars)))
  115.          nil)
  116.          table)
  117.         (setq schars (cons (list table-symbol (nreverse chars))
  118.                    schars)))
  119.       (setq tables (cdr tables))))
  120.     (nreverse schars)))
  121.  
  122. (provide 'symbol-syntax)
  123.